#ifndef _DSWLIVEVIDEO_H
#define _DSWLIVEVIDEO_H

#include "base.h"

#define VGA_FB_DEVICE		"/dev/fb1"
#define TV_FB_DEVICE		"/dev/fb4"

typedef enum{
	VIDEO_UNKNOW_SIGNAL,
	VIDEO_NO_SIGNAL,
	VIDEO_PRESENT,
} EN_VIDEO_SIGNAL;

typedef struct{
	EN_VIDEO_SIGNAL nOldState[MAX_CHANNEL];
	EN_VIDEO_SIGNAL nCurState[MAX_CHANNEL];
	pthread_mutex_t nLock;
} ST_VIDEO_SIGNAL_T, *LPST_VIDEO_SIGNAL_T;

class CDswlivevideo
{
public:
	CDswlivevideo(LPST_ENV_T pEnv);
	virtual ~CDswlivevideo();
private:
	void InitLiveView();
	void UnInitLiveView();
	void setup_win_attr(gm_win_attr_t *win_attr, int ch, int visible, int fullscreen);
	static void cbTimerTask(int fd, short events, void* ctx){((CDswlivevideo*)ctx)->OnTimer(fd, events);};
	void OnTimer(int fd, short events);

	bool InitGUI();
	void UnInitGUI();
	void ConvertDot2Bmp565(unsigned char* pDot, int nlen, unsigned char* pBmp);
	int LoadFont(FILE* fp, wchar_t* pText, int ncount, unsigned char* pDot);
	void DrawOsd(unsigned char * pPos, int nlinesize, int bits, unsigned char* pFontBmp, int nFontCount);

	static void cbLiveNotify(gm_obj_type_t obj_type, int vch, gm_notify_t notify);
	void ShowSignalPic(int nCh);
	void InitVideoSigStruct();
public:
	void SetNoSignal(bool bNoSignal, int nCh);
private:
	LPST_ENV_T m_pEnv;
	timer_param_t m_nTimer;
	void* m_groupfd;
	void* m_bindfd[MAX_CHANNEL];
	void* m_capture_object[MAX_CHANNEL];
	void* m_win_object[MAX_CHANNEL];

	int m_fb_vga;
	unsigned char* m_pVga_buf;
	int m_vga_bufsize;
	int m_vga_cx, m_vga_cy, m_vga_linesize, m_vga_bits;
	gm_rect_t m_vga_rect[MAX_CHANNEL];
	unsigned char* m_vga_start_pos[MAX_CHANNEL];

	unsigned char m_nFontBmp[MAX_CHANNEL][MAX_OSDFONT * 16 * 16 * 2];
	int m_nFontCount[MAX_CHANNEL];
	unsigned char m_nTimeFontBmp[MAX_CHANNEL][MAX_OSDFONT * 16 * 16 * 2];
	int m_nTimeFontCount[MAX_CHANNEL];

	unsigned char m_nDigitalFontBmp[MAX_OSDFONT * 16 * 16 * 2];

	time_t m_oldTime;

	ST_VIDEO_SIGNAL_T m_nVideoSignal;

	int m_nXspin, m_nYspin;
	unsigned char* back_header_data;
	unsigned char* header_data;
	int live_height, live_width;
};

#endif

